﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dia2Lib;

namespace Kokomo.Mirror.PeFormat.Symbols
{
	class InjectedSourceFileEnumerator : SymbolBase, IEnumerator<InjectedSourceFile>
	{
		internal InjectedSourceFileEnumerator(
			IDiaEnumInjectedSources diaSymbolEnum,
			SymbolSource source
			)
			: base(source)
		{
			this._diaInjectedSourceEnum = new ComWrapper<IDiaEnumInjectedSources>(diaSymbolEnum);
		}

		private ComWrapper<IDiaEnumInjectedSources> _diaInjectedSourceEnum;
		private IDiaEnumInjectedSources DiaInjectedSourceEnum { get { return this._diaInjectedSourceEnum.Object; } }

		protected InjectedSourceFile CreateObject(IDiaInjectedSource comObject)
		{
			return new InjectedSourceFile(comObject);
		}


		private InjectedSourceFile _current;
		public InjectedSourceFile Current
		{
			get { return this._current; }
		}

		public void Dispose()
		{
		}

		object System.Collections.IEnumerator.Current
		{
			get { return this._current; }
		}

		public bool MoveNext()
		{
			IDiaInjectedSource obj;
			uint fetched;
			this.DiaInjectedSourceEnum.Next(1, out obj, out fetched);
			if (fetched != 1)
			{
				this._current = null;
				return false;
			}

			this._current = this.CreateObject((IDiaInjectedSource)obj);
			return true;
		}

		public void Reset()
		{
			this.DiaInjectedSourceEnum.Reset();
		}
	}
}
